# ******************************************************************************
# Copyright 2017-2019 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ******************************************************************************
import csv
import re
from abc import abstractmethod
from nlp_architect.models.absa.inference.data_types import SentimentDoc, SentimentSentence
[docs]class Anonymiser(object):
"""Abstract class for anonymiser algorithm, intended for privacy keeping."""
[docs] @abstractmethod
def run(self, text):
pass
def _ui_format(sent: SentimentSentence, doc: SentimentDoc) -> str:
"""Get sentence as HTML with 4 classes: aspects, opinions, negations and intensifiers."""
text = doc.doc_text[sent.start: sent.end + 1]
seen = set()
for term in sorted([t for e in sent.events for t in e], key=lambda t: t.start)[::-1]:
if term.start not in seen:
seen.add(term.start)
start = term.start - sent.start
end = start + term.len
label = term.type.value + '_' + term.polarity.value
text = ''.join((text[:start], '<span class="', label, '">', text[start: end],
'</span>', text[end:]))
return text